<!DOCTYPE html>
<html>
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <script src="https://cdn.bootcdn.net/ajax/libs/axios/0.21.1/axios.min.js"></script>
  <title></title>
</head>
<body hidden>
  <button onclick="login('admin', 'admin')">登录admin</button>
  <button onclick="login('haiyan@superadmin', 'superadmin@haiyan')">登录sadmin</button>
  <button onclick="outlogin()">退出登录</button>
  <script type="text/javascript">
    function getCookie(name) {
      var arr;
      var reg = new RegExp("(^| )" + name + "=([^;]*)(;|$)");
      if ((arr = document.cookie.match(reg))) {
        return unescape(arr[2]);
      }
      return null;
    }

    function login(u, p) {
      axios({
        method: "post",
        url: '/api/user/login',
        headers: {
          "x-csrf-token": getCookie("csrfToken"),
        },
        data: {
          username: u,
          password: p,
        },
      }).then((result) => {
        console.log(result.data.message, result.data.result)
      }).catch((err) => {
        
      });
    }

    function outlogin() {
      axios({
        method: "post",
        url: "/api/user/outlogin",
        headers: {
          "x-csrf-token": getCookie("csrfToken"),
        },
      }).then((result) => {
        console.log(result.data.message, result.data.result)
      }).catch((err) => {
        
      });
    }
  </script>
</body>
</html>